import React, { Component } from 'react';
import Header from '../../../components/Header/Header';
import { connect } from "react-redux";
import { Toast } from 'react-weui';
import * as actions from '../../../store/action/ambitus';
import '../../../static/css/common.less';
import Utils  from '../../../utils';
import './activity.less';

import axios from '../../../api/api';

class Activity extends Component {
    componentWillMount(){
        this.id = this.props.match.params.id;
        this.props.fetchAmbitusDetail(this.id);
    }


    onShare = () => {
        if(!localStorage.getItem('token')){
            this.props.history.push('/glogin')
        }else{
            const {
                title,
                cover,
                id
            } = this.props.ambitus.detail.activities[0];
            if (!title || !cover) {
                console.log("share detials undefined");
                return;
            }
    
            
            Utils.shareHref({
                //href: `http://huiyouduoapp.com/shop/#activityShare/${this.id}`,
                href: `http://huiyouduoapp.com/shop/redirect.html?app3Redirect=` + encodeURIComponent(`http://huiyouduoapp.com/shop/#activityShare/${this.id}`),
                title: '活动详情',
                content: title,
                thumb: cover,
                picture: cover,
            }).then(()=>{
                axios.post(`api/share/activity/${id}`);
            }).catch(()=>{
                alert('分享失败');
            });
        }
    }
    render() {
        return (
            <div>
                <div className="detail-region">
                    <Header title="活动详情"></Header>
                    <section class="content act-content">
                    {this.props.ambitus.detail.activities.length>0?
                        <div className="content-region">
                            <div className="title">{this.props.ambitus.detail.activities[0].title}</div>
                            <div className="date">{this.props.ambitus.detail.activities[0].created_at}</div>
                            <div className="img"><img src={this.props.ambitus.detail.activities[0].cover}></img></div>
                            <div className="contentBox"></div>
                        </div>
                    :<div className="content-region"></div>}
                        <button className="wechat-share-btn"  onClick={this.onShare}>微信分享<i></i></button>
                    </section>
                </div>
            </div>
        )
    }
}

export default connect((state)=>{return {...state}}, actions)(Activity);